home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wedl120.zip / DEMO2.C < prev    next >
C/C++ Source or Header  |  1991-12-09  |  8KB  |  201 lines

  1.  
  2. /*---------------------------------------------------------------------------*/
  3. /*                                                                           */
  4. /*          WEDL - Windows Enhanced Dialog Library                           */
  5. /*          Copyright (c) 1991, Mike Smedley                                 */
  6. /*          All Rights Reserved                                              */
  7. /*          Module:  DEMO2.C                                                 */
  8. /*                                                                           */
  9. /*---------------------------------------------------------------------------*/
  10.  
  11. #include <windows.h>
  12. #include "wedl.h"
  13. #include "demo.h"
  14. #include "demohelp.h"
  15.  
  16. /*---------------------------------------------------------------------------*/
  17.  
  18. static HFORM define_the_form( HWND hDlg, int curr_rec );
  19. static void fill_media_list_box( HWND hDlg );
  20. static int get_next_record( HWND hDlg, int curr_rec );
  21. static int get_previous_record( HWND hDlg, int curr_rec );
  22. static BOOL okay_to_leave( HWND hDlg, HFORM hform, int new_rec );
  23. static BOOL okay_to_save_changes( HWND hDlg );
  24.  
  25. /*---------------------------------------------------------------------------*/
  26.  
  27. struct albums_t {
  28.     char artist[25+1];
  29.     char title[30+1];
  30.     char label[15+1];
  31.     int copyright;
  32.     char media[15+1];
  33. };
  34.  
  35. static struct albums_t albums[] = {
  36.     { "Aerosmith", "Pump", "Geffen", 1989, "Compact Disc" },
  37.     { "Bell Biv Devoe", "Poison", "MCA", 1990, "Cassette" },
  38.     { "The Cure", "Disintegration", "Elektra", 1989, "Compact Disc" },
  39.     { "Front 242", "Front by Front", "Wax Trax", 1988, "Compact Disc" },
  40.     { "INXS", "Kick", "Atlantic", 1987, "Cassette" },
  41.     { "Judas Priest", "Screaming for Vengeance", "Columbia", 1982, "Record" },
  42.     { "Kenny G", "Live", "Arista", 1989, "Compact Disc" },
  43.     { "R.E.M.", "Out of Time", "Warner Bros.", 1991, "Cassette" },
  44.     { "Sex Pistols", "Never Mind the Bollocks", "Warner Bros.", 1977, "Record" },
  45.     { "Van Halen", "OU812", "Warner Bros.", 1988, "Compact Disc" },
  46. };
  47.  
  48. static PSTR media[] =
  49.     { "Compact Disc", "Cassette", "Record", "DAT", "Open Reel", "8-Track", NULL };
  50.  
  51. /*---------------------------------------------------------------------------*/
  52.  
  53. int FAR PASCAL DialogProc2( HWND hDlg, unsigned message, WORD wParam,
  54.                             LONG lParam )
  55. {
  56.     static HFORM hform = NULL;
  57.     static int curr_rec = 0;
  58.     int new_rec;
  59.  
  60.     switch( message ) {
  61.         case WM_INITDIALOG:
  62.             hform = define_the_form( hDlg, curr_rec );
  63.             fill_media_list_box( hDlg );
  64.             return( TRUE );
  65.  
  66.         case WM_COMMAND:
  67.             dproc_enter_wm_command( hform, wParam, lParam );
  68.             switch( wParam ) {
  69.                 case IDOK:
  70.                     dproc_enter_idok( hform );
  71.                     if( !form_in_error_cond( hform ) ) {
  72.                         if( form_validate( hform ) != NULL ) break;
  73.                         if( form_has_changed( hform ) )
  74.                             if( okay_to_save_changes( hDlg ) )
  75.                                 form_process( hform );
  76.                         EndDialog( hDlg, TRUE );
  77.                         form_terminate( hform );
  78.                     }
  79.                     return( TRUE );
  80.                 case IDCANCEL:
  81.                     dproc_enter_idcancel( hform );
  82.                     EndDialog( hDlg, TRUE );
  83.                     form_terminate( hform );
  84.                     return( TRUE );
  85.                 case ID_PREVIOUS:
  86.                     new_rec = get_previous_record( hDlg, curr_rec );
  87.                     if( new_rec != -1 ) {
  88.                         if( !okay_to_leave( hDlg, hform, new_rec ) ) break;
  89.                         curr_rec = new_rec;
  90.                     }
  91.                     PostMessage( hDlg, WM_COMMAND, GOTO_ARTIST, 0 );
  92.                     return( TRUE );
  93.                 case ID_NEXT:
  94.                     new_rec = get_next_record( hDlg, curr_rec );
  95.                     if( new_rec != -1 ) {
  96.                         if( !okay_to_leave( hDlg, hform, new_rec ) ) break;
  97.                         curr_rec = new_rec;
  98.                     }
  99.                     PostMessage( hDlg, WM_COMMAND, GOTO_ARTIST, 0 );
  100.                     return( TRUE );
  101.                 case GOTO_ARTIST:
  102.                     SetFocus( GetDlgItem( hDlg, ID_ARTIST ) );
  103.                     return( TRUE );
  104.  
  105.             }
  106.             break;
  107.     }
  108.     return( FALSE );
  109. }
  110.  
  111. /*---------------------------------------------------------------------------*/
  112.  
  113. static HFORM define_the_form( HWND hDlg, int curr_rec )
  114. {
  115.     HFORM hform;
  116.  
  117.     hform = form_begin( hDlg );
  118.     form_set_help( hform, "demohelp.hlp" );
  119.     field_define( hform, ID_RECNO, &curr_rec, DT_INTEGER,
  120.                   "999", FDF_UPDATE | FDF_NOTEDIT, NULL, 0, HELPID_RECNO );
  121.     field_define( hform, ID_ARTIST, albums[curr_rec].artist, DT_STRING,
  122.                   "?(25)", FDF_NOTBLANK | FDF_CONDUPD, NULL, 0, HELPID_ARTIST );
  123.     field_define( hform, ID_TITLE, albums[curr_rec].title, DT_STRING,
  124.                   "?(30)", FDF_CONDUPD, NULL, 0, HELPID_TITLE );
  125.     field_define( hform, ID_LABEL, albums[curr_rec].label, DT_STRING,
  126.                   "?(15)", FDF_CONDUPD, NULL, 0, HELPID_LABEL );
  127.     field_define( hform, ID_COPYRIGHT, &albums[curr_rec].copyright, DT_INTEGER,
  128.                   "<1><9>99", FDF_COMPLETE | FDF_UPDATE, NULL, 0, HELPID_COPR );
  129.     field_define( hform, ID_MEDIA, albums[curr_rec].media, DT_STRING,
  130.                   "?(15)", FDF_COMBO | FDF_NOTBLANK | FDF_CONDUPD, NULL, 0, HELPID_MEDIA );
  131.     statmsg_define( hform, ID_INSERT,   SM_INSERT,   "[Ins]",  "" );
  132.     statmsg_define( hform, ID_CAPSLOCK, SM_CAPSLOCK, "[Caps]", "" );
  133.     statmsg_define( hform, ID_NUMLOCK,  SM_NUMLOCK,  "[Num]",  "" );
  134.     form_end( hform );
  135.     return( hform );
  136. }
  137.  
  138. /*---------------------------------------------------------------------------*/
  139.  
  140. static void fill_media_list_box( HWND hDlg )
  141. {
  142.     int i;
  143.     for( i = 0 ; media[i] != NULL ; i++ ) {
  144.         SendMessage( GetDlgItem( hDlg, ID_MEDIA ), CB_ADDSTRING, 0,
  145.                      (LONG) ( (LPSTR) media[i] ) );
  146.     }
  147. }
  148.  
  149. /*---------------------------------------------------------------------------*/
  150.  
  151. static int get_next_record( HWND hDlg, int curr_rec )
  152. {
  153.     int next_rec, last_rec;
  154.  
  155.     next_rec = curr_rec + 1;
  156.     last_rec = ( sizeof( albums ) / sizeof( albums[0] ) ) - 1;
  157.     if( next_rec > last_rec ) {
  158.         MessageBeep( 0 );
  159.         MessageBox( hDlg, "End of File", NULL, MB_ICONEXCLAMATION | MB_OK );
  160.         return( -1 );
  161.     }
  162.     return( next_rec );
  163. }
  164.  
  165. /*---------------------------------------------------------------------------*/
  166.  
  167. static int get_previous_record( HWND hDlg, int curr_rec )
  168. {
  169.     int prev_rec;
  170.  
  171.     prev_rec = curr_rec - 1;
  172.     if( prev_rec < 0 ) {
  173.         MessageBeep( 0 );
  174.         MessageBox( hDlg, "Top of File", NULL, MB_ICONEXCLAMATION | MB_OK );
  175.         return( -1 );
  176.     }
  177.     return( prev_rec );
  178. }
  179.  
  180. /*---------------------------------------------------------------------------*/
  181.  
  182. static BOOL okay_to_leave( HWND hDlg, HFORM hform, int new_rec )
  183. {
  184.     if( form_validate( hform ) != NULL ) return( FALSE );
  185.     if( form_has_changed( hform ) )
  186.         if( okay_to_save_changes( hDlg ) ) form_process( hform );
  187.     form_terminate( hform );
  188.     define_the_form( hDlg, new_rec );
  189.     return( TRUE );
  190. }
  191.  
  192. /*---------------------------------------------------------------------------*/
  193.  
  194. static BOOL okay_to_save_changes( HWND hDlg )
  195. {
  196.     return( MessageBox( hDlg, "Record has changed.  Save changes?",
  197.                         "Record Has Changed",
  198.                         MB_ICONQUESTION | MB_YESNO ) == IDYES );
  199. }
  200.  
  201.